package cn.zhaozhiqi.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.zhaozhiqi.mapper.CustomerCarMapper;
import cn.zhaozhiqi.pojo.domain.CustomerCar;
import cn.zhaozhiqi.pojo.dto.AddCarDto;
import cn.zhaozhiqi.service.ICustomerCarService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 客户车辆 服务实现类
 * </p>
 *
 * @author zhaozhiqi
 * @since 2024-12-21
 */
@Service
public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, CustomerCar> implements ICustomerCarService {

    /**
     * 新增车辆信息
     * @param dto
     * @return
     */
    @Override
    public Boolean addCarMessage(AddCarDto dto) {
        long customerId = StpUtil.getLoginIdAsLong();
        //存储汽车相关信息
        CustomerCar customerCar = new CustomerCar();
        BeanUtils.copyProperties(dto,customerCar);
        customerCar.setCustomerId(customerId);
        customerCar.setCreateTime(new Date());
        super.save(customerCar);
        return true;
    }

    @Override
    public Object searchCarList() {
        long customerId = StpUtil.getLoginIdAsLong();
        List<CustomerCar> list = super.list(new LambdaQueryWrapper<CustomerCar>().eq(CustomerCar::getCustomerId, customerId));
        return list;
    }
}
